package com.zs4sdk.statistics;

import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.util.Log;

import com.common.library.util.ActivityHelper;
import com.kochava.base.Tracker;
import com.zs4gamesdk.R;
import com.zs4sdk.common.Zs4GameSharePreferences;

/**
 * Created by Administrator on 2018/4/28.
 */

 class Kochavatracker {
    public static final String Kochavatracker_APP_KEY = "ko-zyeie7v4";
    public static String getDeviceId(){
        String deviceId =  Tracker.getDeviceId();
        return deviceId;
    }

    public static void setRegisterWithAccountID(String accountId){
       // Tracking.setRegisterWithAccountID(accountId);
        String CustomEvent = "AccountRegist_"+accountId;
        Tracker.sendEvent(new Tracker.Event(CustomEvent));
    }

    public static void setLoginSuccessBusiness(String accountId){
       // Tracking.setLoginSuccessBusiness(accountId);
        String CustomEvent = "AccountLogin_"+accountId;
        Tracker.sendEvent(new Tracker.Event(CustomEvent));
    }

    public static void initWithKeyAndChannelId(Context context){
        String appkey =readKochavatrackerKey(context);
        if(appkey == null){
            ActivityHelper.showLongToast(context,context.getString(R.string.zs4Game_right_reyun_appkey));
            appkey = Kochavatracker_APP_KEY;
        }
       // Tracking.initWithKeyAndChannelId(context.getApplicationContext(),appkey,"_default_");
        Tracker.configure(new Tracker.Configuration(context.getApplicationContext())
                .setAppGuid(appkey)
                .setLogLevel(Tracker.LOG_LEVEL_INFO));
    }
    public static void initWithKeyAndChannelId(Context context,String appKey){
       // Tracking.initWithKeyAndChannelId(context.getApplicationContext(),appKey,"_default_");
        Tracker.configure(new Tracker.Configuration(context.getApplicationContext())
                .setAppGuid(appKey)
                .setLogLevel(Tracker.LOG_LEVEL_INFO));
    }
    public static void exitSdk(){

    }
    private static String readKochavatrackerKey(Context context) {
        try {
            ApplicationInfo appInfo = context.getPackageManager()
                    .getApplicationInfo(context.getPackageName(), PackageManager.GET_META_DATA);
            if (appInfo != null) {
                return appInfo.metaData.getString("kochava.appkey");
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    private void Custom(){
        /**
         * Custom Event改成你们需要定义的event name，  addCustom可有可无   如果要在这个事件内传参数的话  可以用addCustom  不需要的话就去掉就好

         */
        Tracker.sendEvent(new Tracker.Event("Custom Event")
                .addCustom("custom_key", "custom_value")
        );

    }
}
